﻿namespace Jhong.FunMVC
{
    using System.Collections.Generic;
    using OQuertyString = Microsoft.Owin.QueryString;

    public class QueryString
    {
        public OQuertyString OwinQueryString { get; private set; }

        public QueryString(OQuertyString queryString)
        {
            this.OwinQueryString = queryString;
            foreach (var s1 in queryString.Value.Split('&'))
            {
                if (string.IsNullOrWhiteSpace(s1)) continue;
                var index = s1.IndexOf('=');
                if (index < 0) continue;
                this._data.Add(s1.Substring(0, index), s1.Substring(index + 1));
            }
        }

        private IDictionary<string, string> _data = new Dictionary<string, string>();

        public string this[string key]
        {
            get
            {
                string value = null;
                if (this._data.TryGetValue(key, out value)) return value;
                return null;
            }
        }
    }
}